package com.qidianit.mes.pro.controller;

import com.github.pagehelper.PageInfo;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.pro.TaskList;
import com.qidianit.mes.pro.service.TaskListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Description:
 * @Author: shanzhe
 * @Date: 2025/9/24 - 18:56
 */
@RestController
@RequestMapping("taskList")
public class TaskListController {
    @Autowired
    private TaskListService taskListService;

    @GetMapping("/list")
    public Result<PageInfo<TaskList>> seleteTaskList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, // 【核心修正】每页数量，默认值为 10
                                                     @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,   // 【核心修正】当前页码，默认值为 1
                                                     @RequestParam(value = "productionOrderId",required = false) Long productionOrderId,
                                                     @RequestParam(value = "processId",required = false) Long processId,
                                                     @RequestParam(value = "workflowId",required = false) Integer workflowId) {
        return Result.success(taskListService.selectTaskPage(pageNum,pageSize,productionOrderId,processId,workflowId));
    }

    @PostMapping("/add")
    public Result<TaskList> addTaskListByProductionOrderIdAndProcessId(@RequestBody TaskList taskList) {
        taskList.setUpdateTime(LocalDateTime.now());
        int result = taskListService.addTaskListByProductionOrderIdAndProcessId(taskList);
        return result==1?Result.success():Result.error("操作失败");
    }

    @PutMapping("/update")
    public Result updateTaskCodeById(@RequestBody TaskList taskList) {
        int result = taskListService.updateTaskCodeById(taskList);
        return result==1?Result.success():Result.error("操作失败");
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteTaskListById(@PathVariable("id") Long id) {
        int result = taskListService.deleteTaskListById(id);
        return result == 1?Result.success():Result.error("操作失败");
    }
    @DeleteMapping("/batchDelete/{ids}")
    public Result batchDeleteTaskListByIds(@PathVariable("ids") List<Long> ids) {
        int result = taskListService.batchDeleteTaskListByIds(ids);
        return result == 1?Result.success():Result.error("操作失败");
    }
}
